import { http } from "@/utils/http";
import { baseUrlApi, sseUrlApi } from "./utils";

export type DataResult = {
  success: boolean;
  data?: Array<any>;
  errMsg: "";
};

export type UserStatusResult = {
  success: boolean;
  data?: number;
  errMsg: "";
};

export type PageResult = {
  success: boolean;
  data: {
    title?: string; //返回额外的题目用于展示
    /** 列表数据 */
    list: Array<any>;
    /** 总数 */
    total?: number;
  };
  errMsg: "";
};

export type QuestionResult = {
  success: boolean;
  data?: {
    id: number;
    questionid: string;
    type: number;
    score: number;
    paperid: string;
    childIndex?: number;
    childId?: string;
    childType?: number;
    title?: string;
    childTitle?: string;
    choiceList?: Array<any>;
    answer?: any;
  };
  errMsg: "";
};

export type PaperResult = {
  success: boolean;
  data?: Array<any>;
  times?: number;
  score?: number;
  errMsg: "";
};

/** 查询考试任务列表 */
export const queryProduceTaskByAll = (data?: object) => {
  return http.request<PageResult>("post", baseUrlApi("queryProduceTaskByAll"), {
    data
  });
};

export const checkUserAndPaperStatus = (data?: object) => {
  return http.request<UserStatusResult>(
    "post",
    baseUrlApi("checkUserAndPaperStatus"),
    {
      data
    }
  );
};

export const onStartExamByStudent = (data?: object) => {
  return http.request<PaperResult>("post", baseUrlApi("onStartExamByStudent"), {
    data
  });
};

export const findProducePaperQuestionById = (data?: object) => {
  return http.request<QuestionResult>(
    "post",
    baseUrlApi("findProducePaperQuestionById"),
    {
      data
    }
  );
};

export const updateStudentProduceExamAnswer = (data?: object) => {
  return http.request<DataResult>(
    "post",
    baseUrlApi("updateStudentProduceExamAnswer"),
    {
      data
    }
  );
};

export const onStopExamByStudent = (data?: object) => {
  return http.request<PaperResult>("post", baseUrlApi("onStopExamByStudent"), {
    data
  });
};

export const queryProduceExamByAll = (data?: object) => {
  return http.request<PageResult>("post", baseUrlApi("queryProduceExamByAll"), {
    data
  });
};

export const sendPhoto = (data?: object) => {
  return http.request<DataResult>("post", baseUrlApi("sendPhoto"), {
    data
  });
};

export const closeSseClient = () => {
  return http.request<DataResult>("get", sseUrlApi("closeSse"));
};
